﻿// Decompiled with JetBrains decompiler
// Type: TaleWorlds.CampaignSystem.BarterSystem.Barterables.SetPrisonerFreeBarterable
// Assembly: TaleWorlds.CampaignSystem, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E85F8C15-4DF6-4E9C-A58A-29177E40D07A
// Assembly location: D:\steam\steamapps\common\Mount & Blade II Bannerlord\bin\Win64_Shipping_Client\TaleWorlds.CampaignSystem.dll

using Helpers;
using System.Collections.Generic;
using TaleWorlds.CampaignSystem.Actions;
using TaleWorlds.CampaignSystem.Party;
using TaleWorlds.Core;
using TaleWorlds.Library;
using TaleWorlds.Localization;
using TaleWorlds.SaveSystem;

#nullable disable
namespace TaleWorlds.CampaignSystem.BarterSystem.Barterables
{
  public class SetPrisonerFreeBarterable : Barterable
  {
    [SaveableField(900)]
    private readonly Hero _prisonerCharacter;
    [SaveableField(901)]
    private readonly Hero _ransompayer;

    public override string StringID => "set_prisoner_free_barterable";

    public SetPrisonerFreeBarterable(
      Hero prisonerCharacter,
      Hero captor,
      PartyBase ownerParty,
      Hero ransompayer)
      : base(captor, ownerParty)
    {
      this._prisonerCharacter = prisonerCharacter;
      this._ransompayer = ransompayer;
    }

    public override TextObject Name
    {
      get
      {
        StringHelpers.SetCharacterProperties("PRISONER", this._prisonerCharacter.CharacterObject);
        return new TextObject("{=RwOzeGc3}Release {PRISONER.NAME}");
      }
    }

    public override int GetUnitValueForFaction(IFaction faction)
    {
      float unitValueForFaction = (float) ((double) Campaign.Current.Models.RansomValueCalculationModel.PrisonerRansomValue(this._prisonerCharacter.CharacterObject) * (1.0 + (double) MBMath.ClampFloat(this._prisonerCharacter.CaptivityStartTime.ElapsedWeeksUntilNow, 0.0f, 8f) * 0.30000001192092896) * 0.89999997615814209);
      if (faction == this._prisonerCharacter.MapFaction || faction == this._prisonerCharacter.Clan)
        return (int) unitValueForFaction;
      return faction.MapFaction == this._prisonerCharacter.PartyBelongedToAsPrisoner.MapFaction ? (int) -(double) unitValueForFaction : 0;
    }

    public override ImageIdentifier GetVisualIdentifier()
    {
      return new ImageIdentifier(CharacterCode.CreateFrom((BasicCharacterObject) this._prisonerCharacter.CharacterObject));
    }

    public override string GetEncyclopediaLink() => this._prisonerCharacter.EncyclopediaLink;

    public override void Apply()
    {
      if (!this._prisonerCharacter.IsPrisoner)
        return;
      EndCaptivityAction.ApplyByRansom(this._prisonerCharacter, this._ransompayer);
    }

    internal static void AutoGeneratedStaticCollectObjectsSetPrisonerFreeBarterable(
      object o,
      List<object> collectedObjects)
    {
      ((Barterable) o).AutoGeneratedInstanceCollectObjects(collectedObjects);
    }

    protected override void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
    {
      base.AutoGeneratedInstanceCollectObjects(collectedObjects);
      collectedObjects.Add((object) this._prisonerCharacter);
      collectedObjects.Add((object) this._ransompayer);
    }

    internal static object AutoGeneratedGetMemberValue_prisonerCharacter(object o)
    {
      return (object) ((SetPrisonerFreeBarterable) o)._prisonerCharacter;
    }

    internal static object AutoGeneratedGetMemberValue_ransompayer(object o)
    {
      return (object) ((SetPrisonerFreeBarterable) o)._ransompayer;
    }
  }
}
